home *** CD-ROM | disk | FTP | other *** search
- #include "AmigaMem.h"
- #include <exec/memory.h>
- #include <string.h>
- #ifndef __GNUC__
- #include <clib/exec_protos.h>
- #endif
- #ifdef __GNUC__
- #include <proto/exec.h>
- #endif
- #ifdef __SASC
- #include <proto/exec.h>
- #endif
- #include "minmax.h"
-
- void* Amalloc( ULONG size )
- {
- ULONG *base;
-
- if( base = AllocMem( size+4, MEMF_CLEAR | MEMF_PUBLIC ) )
- {
- base[0] = size + 4;
- return (void *)&base[1];
- }
- else
- return NULL;
- }
-
-
- void* Acalloc( ULONG size, ULONG number )
- {
- return Amalloc( size * number );
- }
-
- char* Astrdup( const char *string )
- {
- char* dup;
- int len;
-
- if( string == NULL ) return NULL;
-
- len = strlen( string );
-
- if( dup = Amalloc( len + 1 ) )
- {
- strcpy( dup, string );
- }
- return dup;
- }
-
-
- void Afree( void* mem )
- {
- ULONG *base;
-
- if( mem )
- {
- base = ( (ULONG *)mem ) -1;
-
- FreeMem( base, base[0] );
- }
- }
-
-
- ULONG Asizeof( void* buf )
- {
- ULONG *base;
-
- if( buf )
- {
- base = ( (ULONG *)buf ) -1;
- return base[0];
- }
- else
- return 0;
- }
-
- void *Arealloc( void *oldbuf, ULONG newsize )
- {
- void *newbuf = Amalloc( newsize );
- ULONG minsize, oldsize;
-
- if( newbuf )
- {
- oldsize = ( oldbuf ) ? Asizeof( oldbuf ) : 0;
- minsize = MIN( oldsize, newsize );
-
- memcpy( newbuf, oldbuf, minsize );
- Afree( oldbuf );
-
- return newbuf;
- }
- else
- return NULL;
-
- }
-